//
//  DOMXMLParser.m
//  UI19_XML数据解析作业
//
//  Created by dllo on 16/4/5.
//  Copyright © 2016年 付冬梅. All rights reserved.
//

#import "DOMXMLParser.h"
#import "GDataXMLNode.h"
#import "CartoonModel.h"

@interface DOMXMLParser ()

@property (nonatomic, retain) NSMutableArray *dataSourceArr;

@end
@implementation DOMXMLParser

+(NSArray *)domXMLParserWithFileName:(NSString *)name fileType:(NSString *)type {
    
    DOMXMLParser *dom = [[DOMXMLParser alloc] init];
    
    dom.dataSourceArr = [NSMutableArray array];
    
    GDataXMLDocument *document = [[GDataXMLDocument alloc] initWithData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:name ofType:type]] options:1 error:nil];
    GDataXMLElement *root = document.rootElement;
    NSArray *arrOfresult = [root elementsForName:@"results"];
    GDataXMLElement *result = arrOfresult[0];
    NSArray *arr = [result elementsForName:@"AlbumInfo"];
    NSLog(@"11111111111%@", arr);
    for (GDataXMLElement *element in arr) {
        CartoonModel *model = [[CartoonModel alloc] init];
        model.name = [[[element elementsForName:@"name"] lastObject] stringValue];
        model.desc = [[[element elementsForName:@"desc"] lastObject] stringValue];
        model.picUrl = [[[element elementsForName:@"picUrl"] lastObject] stringValue];
        [dom.dataSourceArr addObject:model];
    }
    return dom.dataSourceArr;
}



@end
